package com.leadership.api.service.impl;

import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Service;
import com.demo2do.core.entity.page.Page;
import com.leadership.api.entity.ReportSearch;
import com.leadership.api.service.ReportService;

/**
 * 
 * @author Rockett
 *
 */
@Service("reportService")
public class ReportServiceImpl extends DataServiceImpl<Object> implements ReportService{


    /* (non-Javadoc)
     * @see com.training.admin.service.ReportService#count(com.training.admin.entity.search.ReportSearch)
     */
    @Override
    public int count(ReportSearch search) {
        String sentence = search.buildSentenceTemplate();
        Map<String, Object> parameters = search.buildParameters();
        return genericDaoSupport.count(sentence, parameters);
    }

    /* (non-Javadoc)
     * @see com.training.admin.service.ReportService#search(com.training.admin.entity.search.ReportSearch, com.demo2do.core.entity.page.Page)
     */
    @SuppressWarnings("rawtypes")
    @Override
    public List search(ReportSearch search, Page page) {
        // 1. build parameters
        String sentence = search.buildSentenceTemplate();
        Map<String, Object> parameters = search.buildParameters();
        
        // 2. do query
        List records = genericDaoSupport.searchForList(sentence, parameters, page.getBeginIndex(), page.getEveryPage());
        page.calculate();
        return records;

    }
    
    /* (non-Javadoc)
     * @see com.training.admin.service.ReportService#search(com.training.admin.entity.search.ReportSearch, com.demo2do.core.entity.page.Page)
     */
    @SuppressWarnings("rawtypes")
    @Override
    public List searchForExport(ReportSearch search) {
        // 1. build parameters
        String sentence = search.buildSentenceTemplate();
        Map<String, Object> parameters = search.buildParameters();
        
        // 2. do query
        List records = genericDaoSupport.searchForList(sentence, parameters);
        return records;

    }

}
